package com.situ.util;

import com.alibaba.fastjson2.JSON;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

public class ServletUtils {
    public  static void renderJson( HttpServletResponse resp, Object data) throws IOException {
        resp.setContentType("application/json;charset=UTF-8");

        //请求转发
        String json = JSON.toJSONString(data);
        PrintWriter out = null;
        try {
            out = resp.getWriter();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        out.write(json);
        out.flush();
    }
}
